<%--
  Created by IntelliJ IDEA.
  User: 门铎
  Date: 2016/6/24
  Time: 9:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Title</title>
    <!-- BOOTSTRAP STYLES-->
    <link href="${pageContext.request.contextPath}/css/bootstrap.css" rel="stylesheet" />
    <!-- FONTAWESOME STYLES-->
    <link href="${pageContext.request.contextPath}/css/font-awesome.css" rel="stylesheet" />
    <!-- PAGE LEVEL STYLES -->
    <link href="${pageContext.request.contextPath}/css/bootstrap-fileupload.min.css" rel="stylesheet" />
    <!--CUSTOM BASIC STYLES-->
    <link href="${pageContext.request.contextPath}/css/basic.css" rel="stylesheet" />
    <!--CUSTOM MAIN STYLES-->
    <link href="${pageContext.request.contextPath}/css/custom.css" rel="stylesheet" />
</head>
<style>
    .title-a{
        font-size: 14px;
        color: #00b7ee;
        text-decoration: none;
    }
</style>
<body>
<div id="wrapper">
    <jsp:include page="../manage/nav-top.jsp"/>
    <jsp:include page="../manage/nav.jsp"/>
    <!-- /. NAV SIDE  -->
    <div id="page-wrapper">
        <div id="page-inner">
            <div class="row">
                <div class="col-md-12">
                    <ol class="breadcrumb">
                        <li><a href="#">首页</a></li>
                        <li><a href="#">学术成果</a></li>
                        <li class="active">编辑</li>
                    </ol>
                    <hr />
                    <ul class="nav nav-pills">
                        <li>
                            <a href="${pageContext.request.contextPath}/cimv/paper/list/0">
                                <i class="glyphicon glyphicon-user"></i>论文列表
                            </a>
                        </li>
                        <li  <c:if test="${flag==0}">class="active"</c:if>>
                            <a href="${pageContext.request.contextPath}/cimv/paper/new/0">
                                <i class="glyphicon glyphicon-plus"></i>新建论文
                            </a>
                        </li>
                        <li>
                            <a href="${pageContext.request.contextPath}/cimv/paper/list/1">
                                <i class="glyphicon glyphicon-user"></i>会议列表
                            </a>
                        </li>
                        <li <c:if test="${flag==1}">class="active"</c:if>>
                            <a href="${pageContext.request.contextPath}/cimv/paper/new/1">
                                <i class="glyphicon glyphicon-plus"></i>新建会议
                            </a>
                        </li>
                        <li>
                            <a href="${pageContext.request.contextPath}/cimv/paper/direction/list">
                                <i class="glyphicon glyphicon-user"></i>分类列表
                            </a>
                        </li>
                        <li>
                            <a href="${pageContext.request.contextPath}/cimv/paper/direction/new">
                                <i class="glyphicon glyphicon-user"></i>新增分类
                            </a>
                        </li>
                    </ul>
                    <hr />
                </div>
            </div>
            <!--学术论文-->
            <c:if test="${paper.paperFlag==0}">
                <!-- /. ROW  -->
                <div class="row">
                    <div class="col-md-12">
                        <div class="form-group col-md-6">
                            <label>排序序号</label>
                            <input class="form-control"  type="text" id="sid" value="${paper.sid}">
                            <p class="help-block"></p>
                        </div>
                        <div class="form-group col-md-6">
                            <label>发表年份</label>
                            <input class="form-control"  type="text" id="paperYear" value="${paper.paperYear}">
                            <p class="help-block"></p>
                        </div>
                        <div class="form-group col-md-12">
                            <label>论文作者</label>
                            <input class="form-control"  type="text" id="persion" value="${paper.persion}">
                            <p class="help-block"></p>
                        </div>
                        <div class="form-group col-md-12">
                            <label>论文名称</label>
                            <input class="form-control"  type="text" id="name" value="${paper.name}">
                            <p class="help-block"></p>
                        </div>
                        <div class="form-group col-md-12">
                            <label>刊物名称</label>
                            <input class="form-control"  type="text" id="journal" value="${paper.journal}">
                            <p class="help-block"></p>
                        </div>
                        <div class="form-group col-md-12">
                            <label>发表时间</label>
                            <input class="form-control"  type="text" id="paperTime" value="${paper.paperTime}">
                            <p class="help-block"></p>
                        </div>
                        <div class="form-group col-md-12">
                            <label>所属分类</label>
                            <select class="form-control" id="oid">
                                <c:forEach var="op" items="${options}">
                                    <option value="${op.id}" <c:if test="${op.id == paper.oid}"> selected = "selected"</c:if>  >${op.title}</option>
                                </c:forEach>
                            </select>
                        </div>
                        <div class="form-group col-md-12">
                            <label>论文上传</label>
                            <div class="fileupload fileupload-new" data-provides="fileupload">
                                <span class="btn btn-file btn-default">
                                    <span class="fileupload-new">选择文件</span>
                                    <span class="fileupload-exists">换一个？</span>
                                    <input type="file" id="pdf" name="pdf" title="${paper.pdf}" multiple value="" />
                                </span>
                                <span class="fileupload-preview" id="pdfBlock"></span>
                            </div>

                        </div>
                        <div class="form-group col-md-12">
                            <button class="btn btn-primary  " data-toggle="modal"
                                    data-target="#myModal">
                                提交
                            </button>
                        </div>

                    </div>
                </div>
                <!-- /. ROW  -->

            </c:if>
            <!--期刊会议-->
            <c:if test="${paper.paperFlag==1}">
                <!-- /. ROW  -->
                <div class="row">
                    <div class="col-md-12">
                        <div class="form-group col-md-6">
                            <label>排序序号</label>
                            <input class="form-control"  type="text" id="sid" value="${paper.sid}">
                            <p class="help-block"></p>
                        </div>
                        <div class="form-group col-md-6">
                            <label>会议年份</label>
                            <input class="form-control"  type="text" id="paperYear" value="${paper.paperYear}">
                            <p class="help-block"></p>
                        </div>
                        <div class="form-group col-md-12">
                            <label>参会人员</label>
                            <input class="form-control"  type="text" id="persion" value="${paper.persion}">
                            <p class="help-block"></p>
                        </div>
                            <%-- <div class="form-group col-md-12">
                                 <label>会议名称</label>
                                 <input class="form-control"  type="text" id="name">
                                 <p class="help-block"></p>
                             </div>--%>
                        <!-- 这个 fix了一下  因为当初说好的不用了 上面注释 -->
                        <input class="form-control"  type="hidden" id="name">
                        <div class="form-group col-md-12">
                            <label>会议组织</label>
                            <input class="form-control"  type="text" id="journal" value="${paper.journal}">
                            <p class="help-block"></p>
                        </div>
                        <div class="form-group col-md-12">
                            <label>会议地点</label>
                            <input class="form-control"  type="text" id="conferenceAdress" value="${paper.conferenceAdress}">
                            <p class="help-block"></p>
                        </div>
                        <div class="form-group col-md-12">
                            <label>会议时间</label>
                            <input class="form-control"  type="text" id="paperTime" value="${paper.paperTime}">
                            <p class="help-block"></p>
                        </div>
                        <div class="form-group col-md-12">
                            <label>所属分类</label>
                            <select class="form-control" id="oid">
                                <c:forEach var="op" items="${options}">
                                    <option value="${op.id}" <c:if test="${op.id==paper.oid}">selected="selected"</c:if>>${op.title}</option>
                                </c:forEach>
                            </select>
                        </div>
                        <div class="form-group col-md-12">
                            <button class="btn btn-primary  " data-toggle="modal"
                                    data-target="#myModal">
                                提交
                            </button>
                        </div>
                    </div>
                </div>
                <!-- /. ROW  -->
            </c:if>
            <!-- 模态框（Modal） -->
            <div class="modal fade" id="myModal" tabindex="-1" role="dialog"
                 aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close"
                                    data-dismiss="modal" aria-hidden="true">
                                &times;
                            </button>
                            <h4 class="modal-title" id="myModalLabel">
                                提示
                            </h4>
                        </div>
                        <div class="modal-body">
                            确定要发布当前论文么？
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default"
                                    data-dismiss="modal">关闭
                            </button>
                            <button  id="update"  type="button" class="btn btn-primary" data-dismiss="modal">
                                确定
                            </button>
                        </div>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal -->
            </div>
            <div  id="myModal2" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
                <div class="modal-dialog modal-sm">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title" id="exampleModalLabel">提示</h4>
                        </div>

                        <div class="modal-body">
                            <div id="myModel2Msg" class="alert alert-success">
                                发布成功！
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- /. PAGE WRAPPER  -->
</div>
<!-- /. WRAPPER  -->

<jsp:include page="../manage/footer.jsp" />
<!-- SCRIPTS -AT THE BOTOM TO REDUCE THE LOAD TIME-->
<!-- JQUERY SCRIPTS -->
<script src="${pageContext.request.contextPath}/js/jquery-1.10.2.js"></script>
<!-- BOOTSTRAP SCRIPTS -->
<script src="${pageContext.request.contextPath}/js/bootstrap.js"></script>
<!-- PAGE LEVEL SCRIPTS -->
<script src="${pageContext.request.contextPath}/js/bootstrap-fileupload.js"></script>
<script src="${pageContext.request.contextPath}/js/jquery.ui.widget.js"></script>
<script src="${pageContext.request.contextPath}/js/jquery.iframe-transport.js"></script>
<script src="${pageContext.request.contextPath}/js/jquery.fileupload.js"></script>
<!-- METISMENU SCRIPTS -->
<script src="${pageContext.request.contextPath}/js/jquery.metisMenu.js"></script>
<!-- CUSTOM SCRIPTS -->
<script src="${pageContext.request.contextPath}/js/custom.js"></script>

<!-- 实例化编辑器 -->
<script type="text/javascript">
    $(function(){
        $('#pdf').change(function(){
            var arr = ".pdf";
            //先验证是不是pdf格式文件
            var file = $(this).val();
            //获取文件后缀名
            var fileExt = file.substring(file.lastIndexOf(".")).toLowerCase();
            if(arr != fileExt){
                alert("您上传的不是pdf格式的图片，请重新上传！");
                $(this).val("");
                //取消掉默认fileupload上传
                return false;
            }else{
                return true;
            }
        });
        $('#pdf').fileupload({
            url:"/cimv/paper/pdf",//文件上传地址，当然也可以直接写在input的data-url属性内
            /* formData:{param1:"p1",param2:"p2"},*///如果需要额外添加参数可以在这里添加
            done:function(e,result){
                //done方法就是上传完毕的回调函数，其他回调函数可以自行查看api
                //注意result要和jquery的ajax的data参数区分，这个对象包含了整个请求信息
                //返回的数据在result.result中，假设我们服务器返回了一个json对象
                //预览图片
                $('#pdfBlock').html(result.result.realName + "上传成功");
                $(this).attr("title",result.result.urlName);
            }
        });
    });


    $(function(){
        $('#update').click(function () {
            var  title = $("#title").val();
            $.ajax({
                url: '/cimv/paper/updatePaper/' + ${paper.id},
                type: 'POST',
                dataType: 'json',
                data: {
                    "sid": $('#sid').val(),
                    "oid": $('#oid').val(),
                    "name": $('#name').val(),
                    "persion": $('#persion').val(),
                    "journal": $('#journal').val(),
                    "paperTime": $('#paperTime').val(),
                    "paperYear": $("#paperYear").val(),
                    "paperFlag": ${paper.paperFlag},
                    "pdf":$("#pdf").attr("title"),
                    "conferenceAdress":$("#conferenceAdress").val()
                }
            }).done(function(data) {
                $('#myModel2Msg').html(""+data.msg);
                $('#myModal2').modal('show');
                setTimeout(function () {
                    $('#myModal2').modal('hide');
                },1000*2);
            })
                    .fail(function(data) {
                        console.log("error");
                    })
                    .always(function() {
                        console.log("complete");
                    });
        });


    });
</script>


</body>

</html>
